package com.staff.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.util.AJAXResultMessage;
import com.common.util.ExtjsPageable;
import com.staff.entity.StaffArchive;
import com.staff.entity.dto.StaffArchiveQueryDTO;
import com.staff.service.IStaffArchiveService;
import com.syslog.aop.SystemServiceLog;

@Controller
@RequestMapping("/staffArchive")
public class StaffArchiveController {
	@Autowired
	private IStaffArchiveService staffArchiveService;
	
	@SystemServiceLog("新建或修改员工档案")
	@RequestMapping("/saveOrUpdate")
	public @ResponseBody AJAXResultMessage saveOrUpdate(StaffArchive staffArchive) 
	{
		try {
			staffArchiveService.saveOrUpdate(staffArchive);
			return new AJAXResultMessage(true,"操作成功");
		} catch (Exception e) {
			return new AJAXResultMessage(false,"操作失败");
		}
	}
	@SystemServiceLog("删除员工")
	@RequestMapping("/delete")
	public @ResponseBody AJAXResultMessage delete(@RequestParam Long id) 
	{
		try {
			StaffArchive staffArchive =  staffArchiveService.findOne(id);
			if(null!=staffArchive) {
				staffArchiveService.delete(staffArchive);
			}
			return new AJAXResultMessage(true,"操作成功！");
		} catch (Exception e) {
			return new AJAXResultMessage(false,"操作失败！");
		}
	}
	@SystemServiceLog("批量删除员工")
	@RequestMapping("/deletes")
	public @ResponseBody AJAXResultMessage deleteStaffs(@RequestParam Long[] ids) 
	{
		try {
			List<Long> idLists = Arrays.asList(ids);
			if(null!=idLists) {
				staffArchiveService.delete(idLists);
			}
			return new AJAXResultMessage(true,"操作成功！");
		} catch (Exception e) {
			return new AJAXResultMessage(false,"操作失败！");
		}
	}
	@SystemServiceLog("查找员工")
	@RequestMapping("/findOne")
	public @ResponseBody StaffArchive findOne(@RequestParam Long id) 
	{
		StaffArchive staffArchive =  staffArchiveService.findOne(id);
		
		return staffArchive;
	}
	
	@SystemServiceLog("查找所有员工")
	@RequestMapping("/findAll")
	public @ResponseBody List<StaffArchive> findAll() 
	{
		 List<StaffArchive> lists =  staffArchiveService.findAll();
		
		return lists;
	}
	//
	//分页查询（需要DTO）
	@SystemServiceLog("分页查询所有员工")
	@RequestMapping("/findPage")
	public @ResponseBody Page<StaffArchiveQueryDTO> findPage(StaffArchiveQueryDTO userQueryDto,ExtjsPageable pageable){
		Page<StaffArchiveQueryDTO> page = staffArchiveService.findAll(StaffArchiveQueryDTO.getSpecification(userQueryDto),pageable.getPageable());
		return page;
	}
}
